package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bean.User;
import service.TaskInfoService;

@WebServlet("/TaskInfoServlet")
public class TaskInfoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public TaskInfoServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		User user = (User) request.getSession().getAttribute("user");
		TaskInfoService service = new TaskInfoService();
		String condition = request.getParameter("condition");
		String page = request.getParameter("page");
		String startTime = request.getParameter("startTime");
		String endTime = request.getParameter("endTime");
		String taskno = request.getParameter("taskno");
		String transportStatus = request.getParameter("transportStatus");
		String payStatus = request.getParameter("payStatus");
		String applyStatus = request.getParameter("applyStatus");
		String lackStatus = request.getParameter("lackStatus");
		String addressee = request.getParameter("addressee");
		String payno = request.getParameter("payno");
		
		String jsonReturn = "";
		switch(condition) {
		case "all" : jsonReturn = service.getTaskJsonByUserId(user.getId(), page, startTime, endTime);break;
		case "alltask" : jsonReturn = service.getAllTaskJson(page, startTime, endTime, taskno, transportStatus, payStatus, applyStatus, lackStatus, addressee, payno);break;
		case "paymoney" : jsonReturn = service.getPayMoneyJson(user.getId());break;
		case "lackmoney" : jsonReturn = service.getLackMoneyJson(user.getId());break;
		case "delivery" : // 领货
		case "applied" : // 未发货
		case "lack" : // 缺货
		case "deliveried" : // 已发货
			jsonReturn = service.getTaskJsonByStatus(user.getId(), condition, page, startTime, endTime);break;
		}
		
		response.getWriter().write(jsonReturn);
	}

}
